package bysj.service;


import bysj.dao.DegreeDao;
import bysj.domain.Degree;
import util.Condition;
import util.JdbcHelper;
import util.Pagination;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

public final class DegreeService {
    private static DegreeDao degreeDao
            = DegreeDao.getInstance();
    private static DegreeService degreeService = null;
    private DegreeService(){}

    public static DegreeService getInstance(){
        if (degreeService == null){
            degreeService =new DegreeService();
        }
        return degreeService;
    }

    public Collection<Degree> findAll(List<Condition>conditionList, Pagination pagination) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        Collection<Degree> degrees = degreeDao.findAll(connection,conditionList,pagination);
        JdbcHelper.close(connection);
        return degrees;
    }

    public Degree find(Integer id) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        Degree degree = degreeDao.find(id,connection);
        JdbcHelper.close(connection);
        return degree;
    }

    public boolean update(Degree degree) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        boolean updated = degreeDao.update(degree,connection);
        JdbcHelper.close(connection);
        return updated;
    }

    public boolean add(Degree degree) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        boolean added = degreeDao.add(degree,connection);
        JdbcHelper.close(connection);
        return added;
    }

    public boolean delete(Integer id) throws SQLException {
        Connection connection = JdbcHelper.getConn();
        boolean deleted = degreeDao.delete(id,connection);
        JdbcHelper.close(connection);
        return deleted;
    }
}

